import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hippo_app/utils/common_util.dart';
import 'package:hippo_app/values/app_value.dart';
import 'package:hippo_app/values/color_value.dart';
import 'package:hippo_app/values/size_value.dart';
import 'package:hippo_app/values/style_value.dart';
import 'package:hippo_app/widgets/ripple_container/ripple_container.dart';

class AppHeader extends StatefulWidget {
  final Widget? child;
  final Widget? appBar;
  final double? height;
  final double? marginLeft;
  final double? marginRight;
  final double? marginTop;
  final double? marginBottom;
  final Widget? appBarRight;
  final Widget? appBarLeft;
  final Widget? appBarCenter;
  final bool backVisible;
  final Color? backColor;
  final BorderRadiusGeometry? borderRadius;

  const AppHeader({
    super.key,
    this.child,
    this.appBar,
    this.marginLeft,
    this.marginBottom,
    this.marginRight,
    this.marginTop,
    this.height,
    this.borderRadius,
    this.appBarCenter,
    this.appBarLeft,
    this.appBarRight,
    this.backVisible = false,
    this.backColor = Colors.white,
  });

  @override
  AppHeaderState createState() => AppHeaderState();
}

class AppHeaderState extends State<AppHeader> {
  toPage(BuildContext context) {
    Navigator.pop(context);
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned(
          child: Container(
            height: widget.height ?? SizeValue.appBarDefaultHeight,
            decoration: BoxDecoration(
              //color: ColorValue.appPrimaryColor,
              borderRadius: widget.borderRadius ?? BorderRadius.zero,
              gradient: StyleValue.appHeaderLinearGradient,
            ),
          ),
        ),
        Positioned(
          top: CommonUtil.getAppHeaderTop(context),
          right: 0,
          child: SvgPicture.asset(
            'assets/images/app/app_header_bg.svg',
            width: 110,
          ),
        ),
        Positioned(
          child: Column(
            children: [
              Container(
                margin: EdgeInsets.only(
                  top: widget.marginTop ?? CommonUtil.getAppHeaderTop(context),
                  bottom: widget.marginBottom ?? SizeValue.appContentPadding,
                  left: widget.marginLeft ?? SizeValue.appContentPadding,
                  right: widget.marginRight ?? 1,
                ),
                child: SizedBox(
                  height: 34.5,
                  child:
                      widget.appBar ??
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          if (widget.backVisible)
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                RippleContainer(
                                  borderRadius: BorderRadius.circular(100),
                                  onTap: () {
                                    toPage(context);
                                  },
                                  child: Icon(
                                    CupertinoIcons.left_chevron,
                                    size: 20,
                                    color: widget.backColor,
                                  ),
                                ),
                                Container(
                                  margin: EdgeInsets.only(left: 5),
                                  child: widget.appBarLeft ?? Container(),
                                ),
                              ],
                            ),
                          widget.appBarCenter ?? Container(),
                          widget.appBarRight ?? Container(),
                        ],
                      ),
                ),
              ),
              widget.child ?? Container(),
            ],
          ),
        ),
      ],
    );
  }
}
